package com.eastfair.builder.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.context.StaticContextUtil;
import com.eastfair.core.exception.BizException;
import com.eastfair.venuebooking.api.WorkOvertimeFeign;
import com.eastfair.venueservice.dto.WorkOvertimeDTO;
import com.eastfair.venueservice.entity.WorkOvertime;
import com.eastfair.venueservice.vo.WorkOvertimeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * <p>
 * 前端控制器
 * 加班申请
 * </p>
 *
 * @author dq
 * @date 2022-10-19
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/workOvertime")
@Api(value = "WorkOvertime", tags = "加班申请")
@PreAuth(replace = "builder:workOvertime:")
public class WorkOvertimeController {

    @Resource
    private WorkOvertimeFeign workOvertimeFeign;

    /**
     * 分页查询加班申请列表VO.
     *
     * @param pageParams the page params
     * @return the r
     */
    @ApiOperation("分页查询加班申请列表VO")
    @PostMapping("/query/workOvertime")
    public R<Page<WorkOvertimeVO>> queryWorkOvertime(@RequestBody PageParams<WorkOvertimeDTO> pageParams) {
        log.info("queryWorkOvertime - 分页查询加班申请列表VO, pageParams={}", pageParams);
        try {
            return workOvertimeFeign.queryWorkOvertime(pageParams);
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 加班单号获取加班详情VO.
     *
     * @param workOvertimeNumber the work overtime number
     * @return the by work overtime number
     */
    @ApiOperation("加班单号获取加班详情VO")
    @GetMapping("/get/{workOvertimeNumber}")
    public R<WorkOvertimeVO> getByWorkOvertimeNumber(@PathVariable("workOvertimeNumber") String workOvertimeNumber) {
        log.info("getByWorkOvertimeNumber - 加班单号获取加班详情VO, workOvertimeNumber={}", workOvertimeNumber);
        try {
            return workOvertimeFeign.getByWorkOvertimeNumber(workOvertimeNumber);
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 保存加班申请.
     *
     * @param workOvertimeDTO the work overtime dto
     * @return the r
     */
    @ApiOperation("保存加班申请")
    @SysLog("添加加班申请")
    @PostMapping("/save")
    public R<WorkOvertime> saveWorkOvertime(@RequestBody WorkOvertimeDTO workOvertimeDTO) {
        log.info("saveWorkOvertime - 保存加班申请, workOvertimeDTO={}", workOvertimeDTO);
        try {
            return workOvertimeFeign.saveWorkOvertime(workOvertimeDTO);
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 更新加班申请.
     *
     * @param workOvertimeDTO the work overtime dto
     * @return the r
     */
    @ApiOperation("更新加班申请")
    @SysLog("修改加班申请")
    @PostMapping("/update")
    public R<WorkOvertime> updateWorkOvertime(@RequestBody WorkOvertimeDTO workOvertimeDTO) {
        log.info("updateWorkOvertime - 更新加班申请, workOvertimeDTO={}", workOvertimeDTO);
        try {
            return workOvertimeFeign.updateWorkOvertime(workOvertimeDTO);
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 提交加班申请.
     *
     * @param workOvertimeDTO the work overtime dto
     * @return the r
     */
    @ApiOperation("提交加班申请")
    @SysLog("提交加班申请")
    @PostMapping("/submit")
    public R<Boolean> submitWorkOvertime(@RequestBody WorkOvertimeDTO workOvertimeDTO) {
        log.info("submitWorkOvertime - 提交加班申请, workOvertimeDTO={}", workOvertimeDTO);
        try {
            return workOvertimeFeign.submitWorkOvertime(workOvertimeDTO);
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 取消申请.
     *
     * @param workOvertimeNumber the work overtime number
     * @return the r
     */
    @ApiOperation("取消申请")
    @SysLog("取消加班申请")
    @GetMapping("/cancel/{workOvertimeNumber}")
    public R<Boolean> cancelWorkOvertime(@PathVariable("workOvertimeNumber") String workOvertimeNumber) {
        log.info("cancelWorkOvertime - 取消申请, workOvertimeNumber={}", workOvertimeNumber);
        try {
            return workOvertimeFeign.cancelWorkOvertime(workOvertimeNumber);
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 更新审核结果.
     *
     * @param workOvertimeDTO the work overtime dto
     * @return the r
     */
    @ApiOperation("更新审核结果")
    @SysLog("审核加班申请")
    @PostMapping("/audit")
    public R<Boolean> auditWorkOvertime(@RequestBody WorkOvertimeDTO workOvertimeDTO) {
        log.info("auditWorkOvertime - 更新审核结果, workOvertimeDTO={}", workOvertimeDTO);
        try {
            return workOvertimeFeign.auditWorkOvertime(workOvertimeDTO);
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 加班单号删除.
     *
     * @param workOvertimeNumber the ids
     * @return the r
     */
    @ApiOperation("加班单号删除")
    @SysLog("删除加班申请")
    @GetMapping("/remove/{workOvertimeNumber}")
    public R<Boolean> removeByWorkOvertimeNumber(@PathVariable("workOvertimeNumber") String workOvertimeNumber) {
        log.info("removeByWorkOvertimeNumber - 加班单号删除, workOvertimeNumber={}", workOvertimeNumber);
        try {
            return workOvertimeFeign.removeByWorkOvertimeNumber(workOvertimeNumber);
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 更新支付结果.
     *
     * @param workOvertimeDTO the work overtime dto
     * @return the r
     */
    @ApiOperation("更新支付结果")
    @PostMapping("/update/payStatus")
    public R<Boolean> updatePayStatus(@RequestBody WorkOvertimeDTO workOvertimeDTO) {
        log.info("updatePayStatus - 更新支付结果, workOvertimeDTO={}", workOvertimeDTO);
        try {
            return workOvertimeFeign.updatePayStatus(workOvertimeDTO);
        } catch (BizException e) {
            return R.fail(e);
        }
    }
}
